﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using BneyBaruch.Ingest.Core.ServiceProcess.Diagnostics;
using System.ServiceModel;
using BneyBaruch.Ingest.MorningLesson.CaptureBox.Services;

namespace BneyBaruch.Ingest.SplittedVideoCaptureBoxService
{
    public partial class SplittedVideoCaptureBoxServerController : DebuggableService
    {
        #region Fields

        private ServiceHost splitedVideoCaptureBoxServerServiceHost = null;
        private SplitedVideoCaptureBoxServer splitedVideoCaptureBoxServer = null;

        #endregion

        #region Constructors

        public SplittedVideoCaptureBoxServerController()
        {
            InitializeComponent();
        }

        #endregion

        #region Start and Stop Overrides

        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            StartServicesHosts();
        }

        protected override void OnStop()
        {
            base.OnStop();
            StopServicesHosts();
        }

        #endregion

        #region Services Hosts Manipulation Methods

        private void StopServicesHosts()
        {
            if (splitedVideoCaptureBoxServerServiceHost.State == CommunicationState.Opened)
                splitedVideoCaptureBoxServerServiceHost.Close();
        }

        private void StartServicesHosts()
        {
            splitedVideoCaptureBoxServer = new SplitedVideoCaptureBoxServer();
            splitedVideoCaptureBoxServerServiceHost = new ServiceHost(splitedVideoCaptureBoxServer);
            splitedVideoCaptureBoxServerServiceHost.Open();
        }

        #endregion
    }
}
